# -*- coding: utf-8 -*-
from utils.utils import *
from utils.config import http_config
import datetime
import time
import json
import requests
import time
import random

null = None
false = False
true = True
def step1():
	# 上报员上报
	print("当前流程:上报员上报信息")
	now = datetime.datetime.now()
	now_time = now.strftime("%m-%d %H:%M:%S")
	token = get_token("06181111111")
	url = "/reporter/submit_potential_info"
	payload = {
		"hospital":"西安交通大学第一附属医院测试1",
		"province":"[\"陕西省\",\"西安市\",\"长安区\"]",
		"department":"急诊",
		"name":f"{now_time}",
		"sex":"男",
		"disease":f"{now_time}",
		"blood":"A（RH阴）",
		"location":""
	}
	res = opo_post(url,payload,token)
	if(res['code']==200):

		url = "/reporter/get_case_history"
		payload = {"pageNum":1,"pageSize":8,"donator_name":"%%"}
		res = opo_post(url,payload,token)
		if(res['code']==200):
			case_id = res['data']['list'][0]['case_id']
			print(f"上报员上报成功,case_id:{case_id}")
			return case_id



def step3():
	# 协调员上报
	print("当前流程:协调员上报信息")
	token = get_token("06182222222")
	now = datetime.datetime.now()
	now_time = now.strftime("%m-%d %H:%M:%S")
	url = "/coordinator/submit_potential_info"
	payload = {
		"hospital": "西安交通大学第一附属医院测试1",
		"province": "[\"广东省\",\"广州市\",\"天河区\"]",
		"department": "ICU",
		"name":f"{now_time}",
		"sex": "男",
		"disease": f"{now_time}",
		"blood": "A（RH阴）",
		"area_id": "64",
		"age": 27,
		"id_card": "[\"身份证号\",\"532224199704121234\"]",
		"donate_hos": "西安交通大学第一附属医院测试2",
		"nation": "苗族",
		"birth": "1997-04-12"
	}
	res = opo_post(url,payload,token)
	if(res['code']==200):
		payload = {
			"flow_list": ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
			"pageNum": "1",
			"pageSize": 6,
			"donator_name": "%%%%",
			"case_code": "%%%%",
			"role": "coordinator"
		}
		url = "/case_utils/coordinator_get_case_list_by_flow"
		res = opo_post(url,payload,token)
		if(res['code']==200):
			case_id = res['data']['list'][0]['case_id']
			print(f"协调员上报成功,case_id:{case_id}")
			return case_id


def step2(case_id):
	# 协调员接受案例＆初步评估
	print("当前流程:协调员接受上报员案例")
	token = get_token("06182222222")
	payload = {
		"case_id":case_id,
		# "fucoordinator_user_id":""
	}
	url = "/coordinator/accept_case"
	res = opo_post(url,payload,token)
	if(res['code']==200):
		print("协调员案例接收成功")
		url = "/api/coordinator/pass_case_first_evulation"
		payload = {
				"case_id": case_id,
				"sex": "男",
				"age": 27,
				"id_card": "[\"身份证号\",\"532224199704121234\"]",
				"donate_hos": "西安交通大学第一附属医院",
				"nation": "汉族",
				"birth": "1997-04-12"
			}
		res = opo_post(url,payload,token)
		if(res['code']==200):
			print("协调员初步评估通过")


def step4(case_id):
	# 评估医师接受案例
	print("当前流程:评估医师接受案例")
	token = get_token("06183333333")
	payload = {
		"case_id":case_id,
		# "fucoordinator_user_id":""
	}
	url = "/evaluator/accept_case"
	res = opo_post(url,payload,token)

	if(res['code']==200):
		print(f"评估医师案例接收成功")


def step5(case_id):
	# 评估医师案例评估
	print("当前流程:评估医师案例评估-表单填写")
	token = get_token("06183333333")
	now = datetime.datetime.now()
	now_time = now.strftime("%m-%d %H:%M:%S")
	url = "/case_utils/get_code_and_name"
	payload = {
		"case_id": case_id
	}
	res = opo_post(url,payload,token)
	if(res['code']==200):
		anlibianhao = res['data']['case_code']

	payload = {
		"case_id": case_id,
		"base_info": '{\"anlibianhao\":\"A-2024-170\",\"xingming\":\"2024-11-24测试\",\"nianling\":\"27\",\"xingbie\":\"男\",\"minzu\":\"汉族\",\"zhengjian\":\"身份证号\",\"shenfenzhenghao\":\"532224199704121234\",\"juanxianyiyuan\":\"西安交通大学第一附属医院测试333\",\"shengao\":\"170\",\"tizhong\":\"70\",\"BMI\":\"24.22\",\"calculateBMI\":\"24.22\",\"xueya\":\"100\",\"xinlv\":\"90\",\"tiwen\":\"37\",\"huxi\":\"20\"}',
		"disease_his": '{\"gaoxueyashi\":\"无\",\"gaoxueyashiYear\":\"不用填\",\"tangniaobingshi\":\"无\",\"tangniaobingshiYear\":\"不用填\",\"shenbingshi\":\"无\",\"shenbingshiYear\":\"不用填\",\"yinjiushi\":\"无\",\"yinjiushiYear\":\"不用填\",\"xiyanshi\":\"无\",\"xiyanshiYear\":\"不用填\",\"qitabingshi\":\"无\",\"qitabingshiYear\":\"不用填\",\"qitabingshiDisease\":\"不用填\",\"shoushushi\":\"无\",\"shoushushiYear\":\"不用填\",\"shoushushiDisease\":\"不用填\"}',
		"death_decide": '{\"hunmichengdu\":\"深昏迷\",\"zizhuhuxi\":\"无呼吸\",\"shenjingfanshe\":\"无神经反射\",\"huxijishiyong\":\"没有使用呼吸机\",\"GCSpingfen\":\"10\"}',
		"hos_stiuation": '{\"yuanfabing\":\"2024-11-24测试\",\"fabingshijian\":\"100\",\"xinfeifusushi\":\"否\",\"xinfeifusushiNumber\":\"不用填\",\"xinfeifusushiTime\":\"不用填\",\"ICU\":\"无\",\"ICUDay\":\"不用填\",\"niaoliangtian\":\"100\",\"niaoliangxiaoshi\":\"100\",\"dixueyaguocheng\":\"无\",\"dixueyaguocheng100\":\"不用填\",\"dixueyaguocheng80\":\"不用填\",\"dixueyaguocheng50\":\"不用填\",\"shengyayao\":\"无\"}',
		"infect_diseases": '{\"Cr\":null,\"BUN\":null,\"Ua\":null,\"GIU\":null,\"Na\":null,\"K\":null,\"AST\":null,\"ALT\":null,\"TBIL\":null,\"DBIL\":null,\"ALB\":null,\"baiqiubizhi\":null,\"GGT\":null,\"CO2CP\":null,\"PT\":null,\"PO2\":null,\"niaodanbaidingxing\":null,\"niaodanbai\":null,\"niaojigan\":null,\"yangbaohedu\":null,\"APTT\":null,\"niaodanbaijigan\":null,\"FIB\":null,\"Hb\":null,\"WBC\":null,\"PLT\":null,\"HBV\":null,\"HCV\":null,\"meidu\":null,\"HIV\":null,\"PaO2\":null,\"FiO2\":null,\"PaO2FiO2\":null,\"calculatePaO2FiO2\":null}',
		"pic_check": '{\"xinzangBchao\":\"无\",\"fubuBchao\":\"无\",\"CTXxian\":\"无\"}',
		"result": "通过",
		"donate_type": "DBCD",
		"big_organ_id": random_big_organ_id_list,
		"death_json": "ss",
		"score_info_json": '{\"xingming\":\"2024-11-24测试\",\"xingbie\":\"男\",\"nianling\":\"27\",\"keshi\":\"ICU\",\"chuanghao\":\"12\",\"zhuyuanhao\":\"11111\",\"linchuangzhenduan\":\"可以捐献\",\"yiyuan\":\"西安交通大学第一附属医院测试4\"}',
		"age_score": "0",
		"disease_score": "0",
		"low_blood_pressure_score": "5",
		"high_blood_pressure_score": "0",
		"jigan_score": "0",
		"cpr_score": "0",
		"total_score": 5
	}

		# 将 base_info 解析为字典
	base_info_dict = json.loads(payload["base_info"])
	hos_stiuation_dict = json.loads(payload['hos_stiuation'])
	score_info_dict = json.loads(payload['score_info_json'])
	# 更新 anlibianhao 的值
	base_info_dict["anlibianhao"] = anlibianhao
	base_info_dict["xingming"] = now_time
	hos_stiuation_dict['yuanfabing'] = now_time
	score_info_dict['xingming'] = now_time
	# 将更新后的字典转换回 JSON 字符串
	payload["base_info"] = json.dumps(base_info_dict, ensure_ascii=False)
	payload["hos_stiuation"] = json.dumps(hos_stiuation_dict, ensure_ascii=False)
	payload['score_info_json'] = json.dumps(score_info_dict, ensure_ascii=False)

	url = "/evaluator/evaluate_case_insert_sheet"
	res = opo_post(url,payload,token)
	if(res['code']==200):
		print("评估成功")

def step6(case_id):
	# 评估医师案例评估上传附件
	print("当前流程:评估医师案例评估-附件上传＆通过案例")
	token = get_token("06183333333")
	params = {'case_id': case_id} 
	url = '/evaluator/upload_file'
	params['pic_type'] = "liver_kidney"
	res = opo_upload(url,params,token)
	params['pic_type'] = "blood_type"
	res = opo_upload(url,params,token)
	params['pic_type'] = "infect"
	res = opo_upload(url,params,token)
	params['pic_type'] = "antigen_test"
	res = opo_upload(url,params,token)
	url = "/evaluator/evaluate_case_acceptable"
	payload = {
		'case_id': case_id
	}
	time.sleep(0.1)
	res = opo_post(url,payload,token)
	if(res['code'] == 200):
		print("成功评估通过案例")
	if(res['code'] == 500):
		print("评估表单还未提交")

def step7(case_id):
	# 协调员 json&file混合上传
	print("当前流程:协调员上传亲属同意前表")
	token = get_token("06182222222")

	url = "/coordinator_form_utils/insert_coordinator_family_before_info_sheet"
	payload = {
		"case_id": case_id,
		"accident": "无",
		"relation": '[\"配偶\"]',
		"disease_type": "脑血管意外",
		"result": "同意",
		"will": "志愿登记同意"
	}
	res = opo_mix_upload_step7(url,payload,token)
	if(res['code']==200):
		print("协调员上传亲属同意前表成功")

def step9(case_id):
	# 协调员 
	print("当前流程:协调员-获取手术前完善表/亲属同意后表")
	token = get_token("06182222222")

	url = "/coordinator_form_utils/upload_coordinator_family_after_info_sheet_file"
	payload = {
		"case_id": case_id,
		"country": "中国",
		"id_code": "532224199704121234",
		"birthday": "1989-01-01",
		"age": "27",
		"nation": "回族",
		"degree": "小学",
		"job": "无",
		"jiguan": "[\"陕西省\",\"西安市\",\"长安区\"]",
		"donate_type": "DBCD",
		"obtain_address": "脚本测试医院",
		"big_organ_id": random_big_organ_id_list,
		"coordinator": "",
		"donate_institution": "脚本测试医院",
		"donate_hospital": "脚本测试医院",
		"honghui_coordinator": "红会协调员1（示例工作单位1）"
	}
	res = opo_mix_upload_step9(url,payload,token)
	if(res['code']==200):
		print("协调员亲属同意后表补充完成")

def step8(case_id):
	# 获取医师出发
	print("当前流程:获取医师-案例出发")
	token = get_token("15002954689")
	url = "/obtainer/get_acceptable_case_list"
	payload = {"pageNum":1,"pageSize":5,"donator_name":"%%","task_state":"%0%","case_code":"%%"}
	res	= opo_post(url,payload,token)
	if(res['code']==200):
		for item in res['data']['list']:
			if item['obtainerCaseBaseEntity']['case_id'] == case_id:
				task_id = item['task_id']
				break	
			else:
				print('没有找到case_id对应的task_id')
				return 0;
		url = '/obtainer/accept_case'
		payload = {"case_id":case_id,"task_id":task_id}
		res	= opo_post(url,payload,token)
		if(res['code']==200):
			print("获取医师出发成功")




def step10(case_id):
	# 超管
	print('当前流程:超级管理员-发起伦理审批')
	token = get_token('15249273495')
	url = "/case_super_admin/start_ethical_audit"
	payload = {"case_id":case_id}
	res = opo_post(url,payload,token)
	if(res['code']==200):
		print("发起伦理审批-成功")

def step11(case_id):
	print("当前流程:伦理委员会审批通过")
	token = get_token("123")
	url = '/ethical/ethical_approve_pass'
	payload = {"case_id":case_id}
	res = opo_post(url,payload,token)
	if(res['code']==200):
		token = get_token("18991610106")
		time.sleep(2)
		res = opo_post(url,payload,token)
		if(res['code']==200):
			print("伦理委员会审批-成功")

def step11_2(case_id):
	print("当前流程:伦理委员会审批不通过")
	token = get_token("123")
	url = '/ethical/ethical_approve_fail'
	payload = {"case_id":case_id,"fail_reason":"脚本测试不通过"}
	res = opo_post(url,payload,token)
	if(res['code']==200):
		token = get_token("18991610106")
		time.sleep(2)
		res = opo_post(url,payload,token)
		if(res['code']==200):
			print("伦理委员会审批-成功")

def step12(case_id):
	print("当前流程:协调员-手术开始")
	token = get_token("06182222222")
	url = "/coordinator/start_operation"
	payload = {"case_id":case_id}
	res = opo_post(url,payload,token)
	if(res['code'] == 200):
		print("协调员开始手术-成功")

def step13(case_id):
	token = get_token("15002954689")
	print("当前流程:获取医师-手术出发")
	url = "/obtainer/finish_obtain_operation"
	payload = {
		"case_id": case_id,
		"finish": "已完成",
		"obtain_add": "111",
		"obtain_man": "1111",
		"json": "{\"checkOrgans\":{\"2222\":true,\"11111\":true,\"肾脏\":true,\"肝脏\":true,\"心脏\":true,\"肺脏\":true,\"角膜\":true,\"胰腺\":true,\"小肠\":true,\"测试新增大器官\":true,\"测试逻辑删除大器官\":true},\"organsOptions\":[\"肾脏\",\"肝脏\",\"心脏\",\"肺脏\",\"角膜\",\"胰腺\",\"小肠\",\"2222\",\"测试新增大器官\",\"测试逻辑删除大器官\",\"11111\"],\"notGainReason\":{},\"liver\":{\"texture\":\"质软\",\"save\":\"冷保存\",\"pressure\":\"\",\"flow\":\"\",\"resistance\":\"\",\"estimate\":\"正常\",\"abnormal\":\"\",\"allocation\":\"西安交大一附院\",\"other\":\"\"},\"kidney1\":{\"texture\":\"硬\",\"textureDegree\":\"轻度\",\"save\":\"冷保存\",\"pressure\":\"\",\"flow\":\"\",\"resistance\":\"\",\"length\":\"111\",\"artery\":\"1\",\"vein\":\"1\",\"ureter\":\"单支\",\"estimate\":\"正常\",\"biopsy\":\"否\",\"biopsyResult\":\"\",\"abnormal\":\"\",\"allocation\":\"西安交大一附院\",\"other\":\"\"},\"kidney2\":{\"texture\":\"硬\",\"textureDegree\":\"轻度\",\"save\":\"冷保存\",\"pressure\":\"\",\"flow\":\"\",\"resistance\":\"\",\"length\":\"11\",\"artery\":\"1\",\"vein\":\"1\",\"ureter\":\"单支\",\"estimate\":\"正常\",\"biopsy\":\"否\",\"biopsyResult\":\"\",\"abnormal\":\"\",\"allocation\":\"西安交大一附院\",\"other\":\"\"},\"heart\":{\"save\":\"冷保存\",\"pressure\":\"\",\"flow\":\"\",\"resistance\":\"\",\"estimate\":\"正常\",\"abnormal\":\"\",\"biopsy\":\"否\",\"biopsyResult\":\"\",\"allocation\":\"西安交大一附院\",\"other\":\"\"},\"lung\":{\"save\":\"冷保存\",\"pressure\":\"\",\"flow\":\"\",\"resistance\":\"\",\"estimate\":\"正常\",\"abnormal\":\"\",\"biopsy\":\"否\",\"biopsyResult\":\"\",\"allocation\":\"西安交大一附院\",\"other\":\"\"}}",
		"check_organ_num": 0,
		"little_organ_id_list": ["1", "2", "5", "6", "7", "10", "11", "12", "13"]
	}

	res = opo_post(url,payload,token)
	if(res['code'] == 200):
		print("获取医师上传手术信息-成功")


def step14(case_id):
	token = get_token("15002954689")
	print("当前流程:获取医师-上传器官获取记录表/手术信息")
	url = "/case_utils/get_big_organ_subcase"
	payload = {"case_id":case_id}	
	res = opo_get(url,payload,token)
	if(res['code'] == 200):
		print("获取医师-器官获取记录表-成功")
		big_organ_list = res['data']
		for big_organ in big_organ_list:
			# print(big_organ)
			big_organ_subcase_id = big_organ['big_organ_subcase_id']
			url = '/obtainer/upload_operation_record_big_organ'
			params = {'big_organ_subacase_id': big_organ_subcase_id, 'is_obtained':'是' }
			opo_mix_upload_step14(url,params,token)

def step15(case_id):
	token = get_token("15002954689")
	print("当前流程:获取医师-选择器官去向")
	url = f"/case_utils/get_little_organ_subcase"
	payload = {"case_id":case_id}	
	res = opo_get(url,payload,token)
	if(res['code'] == 200):
		print("获取医师-移植器官列表获取成功")
		
		little_organ_list = res['data']
		i= 0
		subcase_state_list = ['01','00','11','10']
		for little_organ in little_organ_list:
			# print(big_organ)
			i += 1
			i = i % 4
			time.sleep(2)
			little_organ_id = little_organ['little_organ_subcase_id']
			cold_blood_time = little_organ['cold_blood_time']

			url = '/obtainer/set_little_organ_subcase_state'
			params = {
				"case_id": case_id,
				"little_organ_subcase_id": little_organ_id, 
				"subcase_state":subcase_state_list[i],
				"cold_blood_time": cold_blood_time
			}
			# subcase_state 
			# 01 本院接收
			# 00 本院器用
			# 11 外院接收
			# 10 外院弃用
			opo_post(url,params,token)


def step16(case_id):
	token = get_token("15002954689")
	print("当前流程:获取医师-外院接收")
	now = datetime.datetime.now()
	now_time = now.strftime("%m-%d %H:%M:%S")
	url = "/case_utils/get_little_organ_subcase"
	params = {"case_id":case_id}
	res = opo_get(url,params,token)
	if(res['code'] == 200):
		subcase_list = res['data']
		for subcase in subcase_list:
			if(subcase['subcase_state'] == "11" and subcase['case_id'] == case_id):
				# 外院接收
				little_organ_name = subcase['little_organ_name']
				little_organ_subcase_id = subcase['little_organ_subcase_id']
				print(f"{little_organ_name} 外院接收")
				url = "/obtainer/accept_little_organ_subcase"
				payload = {
					"little_organ_subcase_id": little_organ_subcase_id,
					"name": f"{now_time}测试",
					"is_pilishi": false,
					"sex": "男",
					"blood_type": "A（RH阴）",
					"iden_num": "532224199704121234",
					"age": 27,
					"jiguan": "陕西省西安市长安区",
					"transplant_hos": "脚本测试医院",
					"department": "肾移植科",
					"opre_time": "2024-12-04T09:41:50.617Z",
					"main_doctor": "脚本",
					"second_doctor": "脚本",
					"transplant_organ": "2"
				}
				opo_post(url,payload,token)
				time.sleep(2)



def step17(case_id):
	# 外院弃用
	token = get_token("15002954689")
	print("当前流程:获取医师-外院弃用")
	url = "/case_utils/get_little_organ_subcase"
	params = {"case_id":case_id}
	res = opo_get(url,params,token)
	if(res['code'] == 200):
		subcase_list = res['data']
		for subcase in subcase_list:
			if(subcase['subcase_state'] == "10" and subcase['case_id'] == case_id):
				# 本院弃用
				little_organ_name = subcase['little_organ_name']
				little_organ_subcase_id = subcase['little_organ_subcase_id']
				cold_blood_time = subcase['cold_blood_time']
				print(f"{little_organ_name} 外院弃用")
				url = "/obtainer/set_little_organ_subcase_state"
				payload = {
					"case_id":case_id,
					"little_organ_subcase_id":little_organ_subcase_id,
					"subcase_state":"00",
					"cold_blood_time":cold_blood_time
				}
				opo_post(url,payload,token)
				url = "/obtainer/abandon_little_organ_subcase"
				params= {
					"little_organ_subacase_id":little_organ_subcase_id
				}
				opo_mix_upload_step19(url,params,token)
				time.sleep(2)

def step18(case_id):
	print("当前流程:移植医师-本院接收")
	phone_list = ["15929920556","15029094435","12345678905"]
	for phone in phone_list:
		self_accept(phone)


def self_accept(phone):
	token = get_token(phone)
	now = datetime.datetime.now()
	now_time = now.strftime("%m-%d %H:%M:%S")
	url = "/transplant_doctor/get_department_little_organ_subcase_list"
	payload = {
			"pageNum": "1",
			"pageSize": "5",
			"donator_name": "%%%%",
			"case_code": "%%",
			"subcase_state": "01",
			"flow_list": ["1"] 
		}
	res = opo_post(url,payload,token)
	if(res['data']):
		for subcase in res['data']['list']:
			# print(subcase)
			if(subcase['subcase_state'] == "01" and subcase['case_id'] == case_id):
				url = "/obtainer/accept_little_organ_subcase"
				little_organ_name = subcase['littleOrganInfo']['little_organ_name']
				little_organ_subcase_id = subcase['little_organ_subcase_id']
				print(f"{little_organ_name} 本院接收")
				# 本院接收，填表单
				payload = {
					"little_organ_subcase_id": little_organ_subcase_id,
					"name": f"{now_time}测试",
					"is_pilishi": false,
					"sex": "男",
					"blood_type": "A（RH阴）",
					"iden_num": "532224199704121234",
					"age": 27,
					"jiguan": "陕西省西安市长安区",
					"transplant_hos": "脚本测试医院",
					"department": "肾移植科",
					"opre_time": "2024-12-04T09:41:50.617Z",
					"main_doctor": "脚本",
					"second_doctor": "脚本",
					"transplant_organ": "2"
				}
				opo_post(url,payload,token)
				time.sleep(2)


def step19(case_id):
	# 本院弃用
	token = get_token("15002954689")
	print("当前流程:获取医师-本院弃用")
	url = "/case_utils/get_little_organ_subcase"
	params = {"case_id":case_id}
	res = opo_get(url,params,token)
	if(res['code'] == 200):
		subcase_list = res['data']
		for subcase in subcase_list:
			if(subcase['subcase_state'] == "00" and subcase['case_id'] == case_id):
				# 本院弃用
				little_organ_name = subcase['little_organ_name']
				little_organ_subcase_id = subcase['little_organ_subcase_id']
				cold_blood_time = subcase['cold_blood_time']
				print(f"{little_organ_name} 本院弃用")
				url = "/obtainer/set_little_organ_subcase_state"
				payload = {
					"case_id":case_id,
					"little_organ_subcase_id":little_organ_subcase_id,
					"subcase_state":"00",
					"cold_blood_time":cold_blood_time
				}
				opo_post(url,payload,token)
				url = "/obtainer/abandon_little_organ_subcase"
				params= {
					"little_organ_subacase_id":little_organ_subcase_id
				}
				opo_mix_upload_step19(url,params,token)
				time.sleep(2)




def step20(case_id):
	token = get_token('06182222222')
	print("当前流程:协调员-血样送检")
	url = "/coordinator/blood_check"
	payload = {"case_id": case_id}
	res = opo_post(url,payload,token)
	if(res['code'] == 200):
		print("协调员-血样送检成功")


def step21(case_id):
	token = get_token('13991912927')
	print("当前流程:实验室管理员-接收血样")
	url = "/lab_admin/get_case_need_sample"
	payload = {"pageNum":1,"pageSize":8,"donator_name":"%%","state":"%1%","case_code":"%%"}
	res = opo_post(url,payload,token)
	for item in res['data']['list']:
		if item['case_id'] == case_id:
			sample_id = item['sample_id']
			break	
		else:
			print('没有找到case_id对应的task_id')
			return 0;
	url = "/lab_admin/accept_blood_sample"
	payload = {"__v_isShallow":False,"__v_isRef":True,"_rawValue":{},"_value":{},"sample_id":sample_id}
	res = opo_post(url,payload,token)
	if(res['code'] == 200):
		print("实验室管理员-接收血样成功")

def step22(case_id):
	token = get_token('13991912927')
	print("当前流程:实验室管理员-上传血检结果")
	url = "/lab_admin/update_sample_file"
	payload = {"case_id":case_id}
	res = opo_upload(url,payload,token)
	if(res['code'] == 200):
		print("实验室管理员-上传血检成功")

	


def step23(case_id):
	# 获取结束后完善表
	token = get_token('06182222222')
	print("当前流程:协调员-获取结束后完善表")
	url = "/coordinator_form_utils/insert_coordinator_supplement_sheet"
	payload = {
		"case_id": case_id,
		"hos_number": "12345",
		"death_time": "2024-12-04 15:28",
		"obtain_start_time": "2024-12-02 17:26",
		"obtain_end_time": "2024-12-04 15:12",
		"main_family_name": "123排查",
		"relationship": "[\"配偶\"]",
		"phone": "123456789",
		"address": "陕西省西安市长安区",
		"confirm": null,
		"remains_recovered": "是",
		"remembrance_ceremony": "是",
		"remains_whereboat": "太平间"
	}
	res = opo_mix_upload(url,payload,token)
	if(res['code'] == 200):
		print("获取结束后完善表填写成功")

def step24(case_id):
	token = get_token("15002954689")
	print("当前流程:获取医师-填写信息补充表")
	payload = {
		"case_id": case_id,
		"hot_blood_time": "1",
		"bianyuan_organ_id": "[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\"]",
		"bianyuan_organ": "[\"肾脏\",\"肝脏\",\"心脏\",\"肺脏\",\"角膜\",\"胰腺\"]",
		"organ_donate_case_record_json": "{\"gender\":\"男\",\"age\":\"27\",\"birth\":\"1997-04-12\",\"ethnicOption\":\"回族\",\"nativePlace\":[\"陕西省\",\"西安市\",\"长安区\"],\"nationality\":\"中国\",\"marriage\":\"未婚\",\"career\":\"无\",\"postalCode\":\"1\",\"choseIdenType\":\"身份证号\",\"workUnit\":\"1\",\"hospitalization\":\"否\",\"spHosp\":\"\",\"vaccination\":\"否\",\"relationP\":[\"父\"],\"relationC\":[],\"sun\":\"\",\"daughter\":\"\",\"brother\":\"\",\"sister\":\"\",\"contact\":\"1\",\"contactRela\":\"1\",\"contactPhone\":\"1\",\"contactAddr\":\"1\",\"dateToHos\":\"2024-12-04T06:51:10.977Z\",\"dateToOffice\":\"2024-12-11T06:51:12.902Z\",\"dateToWrite\":\"2024-12-03T06:51:14.073Z\",\"primaryDisease\":\"1\",\"primaryDiseaseDate\":\"2024-12-04T06:51:17.167Z\",\"coma\":\"深昏迷\",\"breath\":\"有\",\"breathMachine\":\"否\",\"reflex\":\"有\",\"hypertension\":\"无\",\"hypertensionYear\":\"\",\"cardiopathy\":\"无\",\"cardiopathyYear\":\"\",\"diabetes\":\"无\",\"diabetesYear\":\"\",\"Cerebrovascular\":\"无\",\"CerebrovascularDiag\":\"\",\"CerebrovascularYear\":\"\",\"tumour\":\"无\",\"liverFailure\":\"无\",\"kidneyFailure\":\"无\",\"smokingHis\":\"无\",\"drinkingHis\":\"无\",\"operationHis\":\"无\",\"operation\":\"\",\"CPRhis\":\"无\",\"CPRnum\":\"\",\"CPRtime\":\"\",\"IDHhis\":\"无\",\"IDH100\":\"\",\"IDH80\":\"\",\"IDH50\":\"\",\"urineH\":\"11\",\"urine24H\":\"11\",\"others\":\"无\",\"otherDisease\":\"\",\"valueT\":\"1\",\"valueP\":\"1\",\"valueR\":\"1\",\"valueR1\":\"1\",\"valueR2\":\"1\",\"valueBp\":\"1\",\"height\":\"170\",\"weight\":\"60\",\"valueBMI\":\"23\",\"KidneyFuncDate\":\"2024-12-04T06:57:07.185Z\",\"KidneyFuncSCr\":\"1\",\"KidneyFuncBUN\":\"1\",\"KidneyFuncUa\":\"1\",\"liverFuncDate\":\"2024-12-04T06:57:08.661Z\",\"liverFuncAST\":\"1\",\"liverFuncALT\":\"1\",\"liverFuncTBIL\":\"1\",\"liverFuncDBIL\":\"1\",\"liverFuncALB\":\"1\",\"electrolyteDate\":\"2024-12-04T07:09:05.534Z\",\"electrolyteNa\":\"1\",\"electrolyteK\":\"1\",\"electrolyteCl\":\"1\",\"electrolyteCO\":\"1\",\"DicDate\":\"2024-12-04T07:09:06.990Z\",\"DicPT\":\"1\",\"DicAPTT\":\"1\",\"DicFIB\":\"1\",\"DicDD\":\"1\",\"CbcDate\":\"2024-12-04T07:09:08.249Z\",\"CbcHb\":\"1\",\"CbcWBC\":\"1\",\"CbcPLT\":\"1\",\"CbcCRP\":\"1\",\"UaDate\":\"2024-12-04T07:09:09.487Z\",\"UaWBC\":\"1\",\"UaRBC\":\"1\",\"UaPro\":\"1\",\"infectiousDate\":\"2024-12-04T07:09:11.531Z\",\"infectiousHBV\":\"阴性\",\"infectiousHCV\":\"阴性\",\"infectiousHIV\":\"阴性\",\"infectiousPRP\":\"阴性\",\"AboDate\":\"2024-12-04T07:09:15.005Z\",\"Abo\":\"1\",\"AboRhD\":\"阴性\",\"microbeDate\":\"2024-12-04T07:09:16.555Z\",\"microbe\":\"1\",\"imagingDate\":\"2024-12-04T07:09:17.785Z\",\"imagingLiver\":\"1\",\"imagingkidney\":\"1\",\"imagingHeart\":\"1\",\"imagingLung\":\"1\"}",
		"donate_record_json": "{\"livingWill\":true,\"relativesWill\":true,\"brainDeath\":true,\"heartDeath\":true,\"agreeState\":\"1\",\"hospital\":\"1\",\"operation\":\"1\",\"operatorDoctor\":\"1\",\"organType\":[true,true,true,true,true,true,true,true,true],\"other\":\"\",\"operaBeginDate\":\"2024-12-04T07:11:38.137Z\",\"operaBeginTime\":\"2024-12-02T09:26:47.000Z\",\"perfusionDate\":\"2024-12-18T07:11:42.573Z\",\"perfusionTime\":\"2024-12-04T07:11:47.000Z\",\"operaEndDate\":\"2024-12-11T07:11:54.502Z\",\"operaEndTime\":\"2024-12-04T07:12:47.000Z\"}",
		"start_time": int(time.time() * 1000),
		"guanzhu_time": int(time.time() * 1000),
		"death_record_json": "{\"donateType\":\"DBD\",\"brainDeath\":{\"place\":\"1\",\"clinicalBrainDeath\":{\"date\":\"2024-12-04T07:10:17.019Z\",\"time\":\"2024-12-04T07:14:12.000Z\",\"doctorFirst\":\"1\",\"doctorSecond\":\"1\",\"result\":\"符合\"},\"checkItems\":{\"eegCheck\":true,\"evoCheck\":true,\"craCheck\":true},\"eegExamination\":{\"date\":\"2024-12-04T07:10:22.505Z\",\"time\":\"2024-12-04T07:13:12.000Z\",\"result\":\"符合\"},\"evokedPotentialExamination\":{\"date\":\"2024-12-04T07:10:26.168Z\",\"time\":\"2024-12-04T08:10:12.000Z\",\"result\":\"符合\"},\"cranialDopplerUltrasound\":{\"date\":\"2024-12-04T07:10:31.224Z\",\"time\":\"2024-12-04T07:11:12.000Z\",\"result\":\"符合\"},\"spontaneousRespirationStimulationTest\":{\"date\":\"2024-12-04T07:10:34.950Z\",\"time\":\"2024-12-04T07:17:12.000Z\",\"doctorFirst\":\"1\",\"doctorSecond\":\"1\",\"result\":\"符合\"}},\"heartDeath\":{\"date\":\"\",\"time\":\"\",\"hospital\":\"\",\"heartStopMinute\":\"\",\"unrecoveredMinute\":\"\",\"deathTime\":\"\"}}"
	}
	url = "/obtain_form_utils/insert_obtain_supplement_sheet"
	res = opo_post(url,payload,token)
	if(res['code'] == 200):
		print("获取医师-填写信息补充表成功")

def step25(case_id):
	token = get_token("15002954689")
	print("当前流程:获取医师-发起归档")
	payload = {
		"case_id": case_id
		}
	url = "/obtainer/archive"
	res = opo_post(url,payload,token)
	if(res['code'] == 200):
		print("获取医师-发起归档成功")

def step26(case_id):
	print("当前流程：超级管理员-补充术后恢复信息")
	token = get_token("15249273495")
	url = "/case_utils/get_little_organ_subcase"
	params = {"case_id":case_id}
	res = opo_get(url,params,token)
	if(res['code'] == 200):
		for little_organ in res['data']:
			# print(little_organ)
			if(little_organ['acceptor_recover'] == "未完成" ):
				print(little_organ['little_organ_name'])
				little_organ_subcase_id = little_organ['little_organ_subcase_id']
				# 这里应该是先用little_organ_subcase_id查acceptor_info_id
				url = "/obtainer/get_accept_little_organ_subcase_info"

				params = {"little_organ_subcase_id": little_organ_subcase_id}
				res = opo_get(url,params,token)
				if(res['code'] == 200):
					acceptor_info_id = res['data'][0]['acceptor_info_id']
					# 这里存疑，返回的是个list，但是目前遇到的length都只有1，可能是接口复用？
					# print(acceptor_info_id,len(res['data']))

					url = "/obtainer/update_accept_little_organ_subcase_info"

					payload = {
							"acceptor_info_id": acceptor_info_id,
							# 这个哪来的？？？
							"is_pilishi": false,
							"sex": "男",
							"blood_type": "A（RH阴）",
							"age": "27",
							"jiguan": "陕西省西安市长安区",
							"transplant_hos": "医院1",
							"department": "肾移植科",
							"opre_time": "2024-12-04T14:30:03.000+00:00",
							"main_doctor": "脚本测试",
							"second_doctor": "脚本测试",
							"transplant_organ": "6",
							"updater": "张静",
							"recover": null,
							"baseInfoCodeJson": null,
							"form1_recover": "正常恢复",
							"little_organ_subcase_id": little_organ_subcase_id
						}
					opo_post(url,payload,token)
					time.sleep(1)
					url = "/case_super_admin/set_recover"
					payload = {
						"little_organ_subcase_id":little_organ_subcase_id,
						"acceptor_info_id":acceptor_info_id,
						"recover":"正常恢复"
					}
					opo_post(url,payload,token)
					time.sleep(1)

def step27(case_id):
	print("当前流程：超级管理员-审核归档")
	token = get_token("15249273495")
	url = f"/case_super_admin/archive?case_id={case_id}"
	payload = {
		"case_id":case_id
	}
	# 这个其实没用上，参数在query里，这么写是懒得改util
	res = opo_post(url,payload,token)
	if(res['code']==200):
		print("超级管理员-归档成功")

def test():
	token = get_token("15249273495")
	url = f"/utils/get_all_little_organ"
	# 这个其实没用上，参数在query里，这么写是懒得改util
	payload = {}
	res = opo_get(url,payload,token)
	for ss in res['data']:
		print(ss)

def summon_global_organ_id_list():
	'''
	保证唯一性，生成一个全局变量的organ_id_list
	'''
	token = get_token("15249273495")
	big_organ_id_list = get_big_organ_id_list(token)

	random_big_organ_id_list = random.sample(big_organ_id_list, 4)
	return random_big_organ_id_list

if __name__ == '__main__':
	random_big_organ_id_list = summon_global_organ_id_list()
	# 全局的organ_id_list

	# case_id = step1()
	# case_id = "1516"
	# step2(case_id)
	# test()

	# case_id= '1635'
	case_id = step3()
	print(case_id)

	step4(case_id)
	step5(case_id)
	step6(case_id)
	step7(case_id)
	step8(case_id)
	step9(case_id)


	step10(case_id)
	step11(case_id)
	# 11 和 11_2 是互斥的
	# step11_2(case_id)

	step12(case_id)
	step13(case_id)
	# step14(case_id)
	# step15(case_id)
	# step16(case_id)
	# step17(case_id)
	# step18(case_id)
	# step19(case_id)

	# step20(case_id)
	# step21(case_id)
	# step22(case_id)
	# step23(case_id)
	# step24(case_id)


	# step25(case_id)
	# step26(case_id)
	# step27(case_id)

'''

'''